<a href='https://github.com/angular/angular.js/edit/v1.6.x/src/Angular.js?message=docs(angular.copy)%3A%20describe%20your%20change...#L822' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>



<a href='https://github.com/angular/angular.js/tree/v1.6.6/src/Angular.js#L822' class='view-source pull-right btn btn-primary'>
  <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
</a>


<header class="api-profile-header">
  <h1 class="api-profile-header-heading">angular.copy</h1>
  <ol class="api-profile-header-structure naked-list step-list">
    
    <li>
      - function in module <a href="api/ng">ng</a>
    </li>
  </ol>
</header>





<div class="api-profile-description">
  <p>Creates a deep copy of <code>source</code>, which should be an object or an array.</p>
<ul>
<li>If no destination is supplied, a copy of the object or array is created.</li>
<li>If a destination is provided, all of its elements (for arrays) or properties (for objects)
are deleted and then all elements/properties from the source are copied to it.</li>
<li>If <code>source</code> is not an object or array (inc. <code>null</code> and <code>undefined</code>), <code>source</code> is returned.</li>
<li>If <code>source</code> is identical to <code>destination</code> an exception will be thrown.</li>
</ul>
<p><br /></p>
<div class="alert alert-warning">
  Only enumerable properties are taken into account. Non-enumerable properties (both on <code>source</code>
  and on <code>destination</code>) will be ignored.
</div>
</div>




<div>
  

  

  <h2 id="usage">Usage</h2>
    
      <p><code>angular.copy(source, [destination]);</code></p>


    

    
<section class="api-section">
  <h3>Arguments</h3>

<table class="variables-matrix input-arguments">
  <thead>
    <tr>
      <th>Param</th>
      <th>Type</th>
      <th>Details</th>
    </tr>
  </thead>
  <tbody>
    
    <tr>
      <td>
        source
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-object">*</a>
      </td>
      <td>
        <p>The source that will be used to make a copy.
                  Can be any type, including primitives, <code>null</code>, and <code>undefined</code>.</p>

        
      </td>
    </tr>
    
    <tr>
      <td>
        destination
        
        <div><em>(optional)</em></div>
      </td>
      <td>
        <a href="" class="label type-hint type-hint-object">Object</a><a href="" class="label type-hint type-hint-array">Array</a>
      </td>
      <td>
        <p>Destination into which the source is copied. If
    provided, must be of the same type as <code>source</code>.</p>

        
      </td>
    </tr>
    
  </tbody>
</table>

</section>
    
    <h3>Returns</h3>
<table class="variables-matrix return-arguments">
  <tr>
    <td><a href="" class="label type-hint type-hint-object">*</a></td>
    <td><p>The copy or updated <code>destination</code>, if <code>destination</code> was specified.</p>
</td>
  </tr>
</table>

  
  
  



  
  <h2 id="example">Examples</h2><p>

<div>
  <plnkr-opener example-path="examples/example-angular-copy"></plnkr-opener>

  <div class="runnable-example"
      path="examples/example-angular-copy"
      module="copyExample"
      name="angular-copy">

  
    <div class="runnable-example-file" 
      name="index.html"
      language="html"
      type="html">
      <pre><code>&lt;div ng-controller=&quot;ExampleController&quot;&gt;&#10;  &lt;form novalidate class=&quot;simple-form&quot;&gt;&#10;    &lt;label&gt;Name: &lt;input type=&quot;text&quot; ng-model=&quot;user.name&quot; /&gt;&lt;/label&gt;&lt;br /&gt;&#10;    &lt;label&gt;Age:  &lt;input type=&quot;number&quot; ng-model=&quot;user.age&quot; /&gt;&lt;/label&gt;&lt;br /&gt;&#10;    Gender: &lt;label&gt;&lt;input type=&quot;radio&quot; ng-model=&quot;user.gender&quot; value=&quot;male&quot; /&gt;male&lt;/label&gt;&#10;            &lt;label&gt;&lt;input type=&quot;radio&quot; ng-model=&quot;user.gender&quot; value=&quot;female&quot; /&gt;female&lt;/label&gt;&lt;br /&gt;&#10;    &lt;button ng-click=&quot;reset()&quot;&gt;RESET&lt;/button&gt;&#10;    &lt;button ng-click=&quot;update(user)&quot;&gt;SAVE&lt;/button&gt;&#10;  &lt;/form&gt;&#10;  &lt;pre&gt;form = {{user | json}}&lt;/pre&gt;&#10;  &lt;pre&gt;master = {{master | json}}&lt;/pre&gt;&#10;&lt;/div&gt;</code></pre>
    </div>
  
    <div class="runnable-example-file" 
      name="script.js"
      language="js"
      type="js">
      <pre><code>// Module: copyExample&#10;angular.&#10;  module(&#39;copyExample&#39;, []).&#10;  controller(&#39;ExampleController&#39;, [&#39;$scope&#39;, function($scope) {&#10;    $scope.master = {};&#10;&#10;    $scope.reset = function() {&#10;      // Example with 1 argument&#10;      $scope.user = angular.copy($scope.master);&#10;    };&#10;&#10;    $scope.update = function(user) {&#10;      // Example with 2 arguments&#10;      angular.copy(user, $scope.master);&#10;    };&#10;&#10;    $scope.reset();&#10;  }]);</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" ng-src="{{getExampleIndex('examples/example-angular-copy')}}" name="example-angular-copy"></iframe>
  </div>
</div>


</p>

</div>


